import {createRouter, createWebHashHistory} from 'vue-router'
import home from '@/views/home'
import login from "@/views/user/login";
import register from "@/views/user/register";
import blog from "@/views/blog";
import newBlog from "@/views/newBlog";
import store from '../store'

const routes = [
    {
        path: '/',
        name: 'home',
        component: home
    },
    {
        path: '/login',
        name: 'login',
        component: login
    },
    {
        path: '/register',
        name: 'register',
        component: register
    },
    {
        path: '/blog',
        name: 'blog',
        component: blog
    },
    {
        path: '/createBlog',
        name: 'newBlog',
        component: newBlog
    },

]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

export default router

if (sessionStorage.getItem("token")){
    store.commit("set_token", sessionStorage.getItem("token"))
}